package com.pb.camera.view;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.pb.camera.R;

import java.lang.reflect.Field;

/**
 * Created by LiuFei on 2016/3/21 0021.
 * 自定义过
 */
public class MyCheckBox extends CheckBox {
    private static final String TAG = "MyCheckBox";

    public MyCheckBox(Context context) {
        super(context);
    }

    public MyCheckBox(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyCheckBox(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public MyCheckBox(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public void setUnListenChecked(boolean checked){
        try {
            Field field = getClass().getSuperclass().getSuperclass().getDeclaredField("mChecked");
            field.setAccessible(true);
            field.setBoolean(this, checked);
            refreshDrawableState();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
